package com.ccp.dev.qbdms.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ccp.dev.core.basic.annotion.Action;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.core.util.log.SysAuditThreadLocalHolder;
import com.ccp.dev.qbdms.consts.ZhiLiangConst;
import com.ccp.dev.qbdms.expimp.util.AbstractExpUtil;
import com.ccp.dev.qbdms.expimp.util.AuxiliaryUtil;
import com.ccp.dev.qbdms.model.vo.SeriousFalProblemVo;
import com.ccp.dev.qbdms.service.WQbdFalProblemresetService;
import com.ccp.dev.system.model.Dictionary;
import com.ccp.dev.system.service.DictionaryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 严重质量问题周进展 信息操作处理控制器
 *
 * @author sun
 * @date 2020-05-06 15:57:36
 */
@Controller
@Action(customModel = "严重质量问题周进展")
@RequestMapping("/qbdms/seriousFalProblem")
public class SeriousFalProblemController  extends SysBaseController {
    @Resource
    private WQbdFalProblemresetService wQbdFalProblemresetService;
    @Resource
    private DictionaryService dictionaryService;

    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_LIST)
    @Action(description = "严重质量问题列表")
    public String viewSeriousFalProblem(ModelMap modelMap){
        List<Dictionary> wtdjDic=dictionaryService.getDicByNodeKey("wtdj",false);
        wtdjDic.remove(0);
        modelMap.put("wtdjDic", JSON.toJSONString(wtdjDic));
        return "seriousFalProblem/list";
    }

    /**
     * 功能描述: 附带检索条件的分页查询
     *
     * @param: [request] http请求
     * @return: java.lang.Object
     * @auther: sun
     * @date: 2020-05-06 15:57:36
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_LIST)
    @ResponseBody
    @Action(description = "附带检索条件的分页查询严重质量问题", detail = "查询严重质量问题列表数据信息<#if success>成功<#else></#if>")
    public Object seriousFalProblemList(HttpServletRequest request) {
        QueryFilter queryFilter = new QueryFilter(request, true);
        ZhiLiangConst.addQueryFilter(queryFilter);
        queryFilter.put("byId",false);
        List<SeriousFalProblemVo> pageDatas = wQbdFalProblemresetService.getSeriousList(queryFilter);
        SysAuditThreadLocalHolder.putParamerter("success", true);
        return success(pageDatas, queryFilter.getPageBean().getTotalCount());
    }

    /**
     * 功能描述: 跳转到导出选择字段页面
     *
     * @return: java.lang.String
     * @auther: hw
     * @date: 2019-12-25 19:21:40
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/export")
    @Action(description="跳转到严重质量问题导出选择字段页面", exectype = "页面跳转日志")
    public String export(HttpServletRequest request, ModelMap modelMap) throws Exception {
        JSONObject jsonObject = AuxiliaryUtil.resolverModel(SeriousFalProblemVo.class);
        modelMap.put("tableInfo",jsonObject.toString());
        return "expImp/add";
    }

    /**
     * 功能描述: 导出未归零质量问题数据信息
     *
     * @param: [request] http请求
     * @return: java.lang.Object
     * @auther: hw
     * @date: 2020-05-25 15:16:44
     */
    @RequestMapping("/exportData")
    @Action(description="导出严重质量问题列表数据信息",detail="导出严重质量问题列表数据信息<#if success>成功<#else></#if>")
    public void export(HttpServletRequest request, HttpServletResponse response) throws Exception{
        SysAuditThreadLocalHolder.putParamerter("success",false);
        String[] id = RequestUtil.getStringAryByStr(request,"id");
        QueryFilter queryFilter = new QueryFilter(request,false);
        JSONArray dataArray = ZhiLiangConst.exportAddConditions(queryFilter,id);
        List<SeriousFalProblemVo> seriousList = this.wQbdFalProblemresetService.getSeriousList(queryFilter);
        if(seriousList.isEmpty()){
            seriousList.add(new SeriousFalProblemVo());
        }
        new AbstractExpUtil() {
            @Override
            public String customAnalysis(String fieldName, String fieldValue) {
                return null;
            }
        }.executeExport(request,response,seriousList,dataArray, AbstractExpUtil.ExpStyle.MANY_SHEET);
        SysAuditThreadLocalHolder.putParamerter("success",true);
    }
}
